package com.shebao.utils.excel;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;

import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

public class PdfUtil {
	public void sc() throws Exception {
		//模板路径
		String templatePath = "d:/template/company.pdf";
		// 生成的新文件路径
		String newPDFPath = "d:/template/3.pdf";
		
		PdfReader reader = new PdfReader(templatePath);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		PdfStamper ps = new PdfStamper(reader, bos);
		
		BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",  
			     BaseFont.NOT_EMBEDDED);
		
		AcroFields s = ps.getAcroFields();  
		s.setField("printDate", "陈伟");  
		
		ps.setFormFlattening(true);  
		ps.close(); 
		FileOutputStream fos = new FileOutputStream(newPDFPath);  
		fos.write(bos.toByteArray());  
	}

	public static void main(String[] args) {
		try {
			new PdfUtil().sc();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
